<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>

        <a-card>
<!--            <div class="table-operator">-->
<!--                <a-button type="primary" icon="plus" @click="handleAdd" v-btnPermission="'bm_001_add_01'"-->
<!--                    >新增</a-button-->
<!--                >-->
<!--                &lt;!&ndash; <p>项目 10 个，已提交资料项目 8 个，资料提交率为：80%</p> &ndash;&gt;-->
<!--            </div>-->
            <list-table
                ref="table"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                :isShowCountBar="false"
                :exportConfig="{ use: true,select: '投标交底',all: '投标交底'}"
                :exportPermission="{ select: 'bm_001_exp_03', all: 'bm_001_exp_03' }"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                        <span
                                slot="serial"
                                slot-scope="text, record, index"
                        >{{ index + 1 }}</span>
              <a-alert class="mb12" type="info" show-icon slot="bottom">
                <template slot="message">
                  总数：<span>{{totols}}</span>
                  待提交：<span>{{totalObj.draft || 0}}</span>
                  审批中：<span>{{totalObj.submitted || 0}}</span>
                  审核通过：<span>{{totalObj.past || 0}}</span>
                  审核不通过：<span>{{totalObj.rejected || 0}}</span>
                </template>
              </a-alert>
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="detailed(record)" v-btnPermission="'bm_001_loo_02'">查看</a>
                        <a @click="addEdit(record)" v-if="(record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST')&&!record.isEdit&&hideBuquBtn()" v-btnPermission="'bm_001_edi_01'">编辑</a>
                        <a @click="handleApproveDetail(record)"
                           v-btn-permission="'bm_001_loo_02'"
                           v-if="!record.isEdit&&record.auditStatus!='DRAFT'">审批信息</a>
                        </MoreButton>
                </span>
            </list-table>
        </a-card>
      <ApprovalDetails
              :title="'审批详情'"
              :business-id="businessId"
              :visible="visibleApprove"
              @cancel="visibleApprove = false"
              @confirm="visibleApprove = false"
      />
    </base-breadcrumb>
</template>

<script>
import { recordList, eliminate, recordCount } from '@/api/businessAffairs/throwMark'
import ApprovalDetails from '@/components/approvalDetails'
import moment from 'moment'

import OrgTreeSelect from '@/components/OrgTreeSelect'
const columns = [
    {
        title: '序号',
        width: '65px',
        scopedSlots: { customRender: 'serial' }
    },
    {
        title: '名称',
        dataIndex: 'name',
    },
    {
        title: '分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '项目名称',
        dataIndex: 'projectName',
    },
    {
        title: '交底日期',
        dataIndex: 'confessDate',
    },
    {
        title: '填报人',
        dataIndex: 'creatorName',
    },
    {
        title: '填报时间',
        dataIndex: 'createTime',
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName'
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
{
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },

    // {
    //     name: '交底组织人',
    //     value: 'organizer',
    //     type: 'input',
    // },
    {
        name: '交底时间',
        value: 'discloseTime',
        type: 'dateRange',
    },
    {
        name: '填报人',
        value: 'creatorName',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange',
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: [
            {
                value: '0',
                label: '待提交审批',
            },
            {
                value: '1',
                label: '审核中',
            },
          {
            value: '2',
            label: '审核通过',
          },
          {
            value: '3',
            label: '审核不通过',
          },
        ],
    },
]
export default {
    name:'a'+Date.now(),
  components: {
    ApprovalDetails
  },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
          visibleApprove: false,
          businessId: '',
            queryParam: {},
            totols: 0,
            totalObj: {},
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)

                if (this.queryParam.startEndDate?.length>0) {
                    requestParameters.createTimeBegin =
                        this.queryParam.startEndDate[0].format('YYYY-MM-DD HH:mm:ss') || void 0
                    requestParameters.createTimeEnd =
                        this.queryParam.startEndDate[1].format('YYYY-MM-DD HH:mm:ss') || void 0
                }
                if (this.queryParam.discloseTime?.length>0) {
                    requestParameters.confessDateBegin =
                        this.queryParam.discloseTime[0].format('YYYY-MM-DD HH:mm:ss') || void 0
                    requestParameters.confessDateEnd =
                        this.queryParam.discloseTime[1].format('YYYY-MM-DD HH:mm:ss') || void 0
                }
                recordCount(requestParameters).then(res=>{
                  this.totalObj = res.data
                })
                return recordList(requestParameters).then((res) => {
                  const statusMap = {
                    'DRAFT': '待提交审批',
                    'SUBMITTED': '审核中',
                    'PAST': '审核通过',
                    'REJECTED': '审核不通过',
                    'ABOLISH': '已发布'
                  }
                  res.data.forEach(item=>{
                    if(!item.creatorName) {
                      item.createTime = ''
                    }
                    item.auditStatusName = statusMap[item.auditStatus]
                  })
                  this.totols = res.totalSize
                    console.log('数据返回对象：', res)
                    return res
                })
            },
        }
    },
    methods: {
      handleApproveDetail(record) {
        this.visibleApprove = true
        this.businessId = record.id
      },
        //搜索
        search(value) {
            console.log(value)
            this.queryParam = value
            this.$refs.table.refresh(true)
        },

        //新增
        handleAdd() {
            this.$router.push('/businessAffairs/throwMark/newIncrease')
        },
        // 查看
        detailed(e) {
            this.$router.push({
                path: '/businessAffairs/throwMark/detailed',
                query: { id: e.id },
            })
        },
        //编辑
        addEdit(e) {
            this.$router.push({
                path: '/businessAffairs/throwMark/newIncrease',
                query: { id: e.id },
            })
        },
        // 删除草稿
        deleteDraft(e) {
            let that = this
            that.$confirm({
                title:"温馨提示",
                content: '你正在进行删除 '+ e.name +' 操作，删除后将不可恢复，确认删除该数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk() {
                    return eliminate({ id: e.id })
                        .then((res) => {
                            that.$message.success('删除成功！')
                            that.$refs.table.refresh(true)
                        })
                        .catch((res) => {
                            that.$message.warning('删除失败！')
                        })
                },
            })
        },
        // // 删除
        // deleteDraft(e) {
        //     eliminate({id:e.id}).then((res) => {
        //         if (res.data.code === 200) {
        //             this.$message.success('删除成功')
        //            this.$refs.table.refresh(true)
        //         } else {
        //             this.$message.error('删除失败')
        //         }
        //     })
        // },
    },
}
</script>

<style lang="less" scoped>
@deep: ~'>>>';
.tool-btns {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}
</style>

